package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Data
public class Integral extends BaseDomain {

    public static final Integer STATE_INCOME = 1; //收入
    public static final Integer STATE_EXPEND = 0; //支出
    private User user;//用户
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd ")
    private Date updateTime;//更新时间
    private Integer changeMoney;//交易金额
    private String detail;//交易明细
    private Long userId;//用户id
    private boolean state;//积分变动时的状态

    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("updateTime", DateUtil.formatDate(updateTime));
        map.put("changeMoney", changeMoney);
        map.put("state", state);
        map.put("detail", detail);
        if (user != null) {
            map.put("userId", user.getId());
        }

        return JSONUtil.toJSONString(map);
    }

    public String getStateName() {
        String msg = "积分商城兑换";
        if (!state) {
            msg = "签到获得";
        }
        return msg;
    }
}